package com.whtq.api.handler.b;

import com.alibaba.fastjson.JSON;
import com.whtq.api.remote.b.BRemoteService;
import com.whtq.db.entity.TBTest;
import com.whtq.db.model.BTestReq;
import com.whtq.front.common.basics.WHTQReturnCode;
import com.whtq.front.common.exception.WHTQException;
import com.whtq.front.common.model.response.PageRes;
import com.whtq.front.common.model.response.WHTQResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by
 *
 * @author wmi
 * @date 2021/9/15 - 15:49.
 * @description
 */
@WHTQResult
@RestController
@RequestMapping(value = "/v1/b")
@Slf4j
public class BTestHandler {

    @Autowired
    BRemoteService bRemoteService;

    /**
     * 保存
     * @param req
     * @return
     */
    @RequestMapping(value = "/saveBtest",method = RequestMethod.POST)
    public int saveBtest(@RequestBody @Validated BTestReq req){
        log.info("saveBtest req:{}", JSON.toJSONString(req));
        return bRemoteService.saveBtest(req);
    }

    /**
     * 查询列表
     * @param req
     * @return
     */
    @RequestMapping(value = "/btestList",method = RequestMethod.POST)
    PageRes btestList(@RequestBody BTestReq req){
        log.info("btestList req:{}",JSON.toJSONString(req));
        return bRemoteService.btestList(req);
    }
    /**
     * 修改
     * @param req
     * @return
     */
    @RequestMapping(value = "/updBtest",method = RequestMethod.POST)
    int updBtest(@RequestBody @Validated BTestReq req){
        log.info("updBtest req:{}",JSON.toJSONString(req));
        return bRemoteService.updBtest(req);
    }
    /**
     * 删除
     * @param req
     * @return
     */
    @RequestMapping(value = "/delBtest",method = RequestMethod.POST)
    Boolean delBtest(@RequestBody @Validated BTestReq req){
        log.info("delBtest req: {}", JSON.toJSONString(req));
        if(req.getIds() != null && req.getIds().size() > 0) {
            return bRemoteService.delBtest(req.getIds());
        } else {
            throw new WHTQException(WHTQReturnCode.PARAMS_ERROR);
        }
    }
    /**
     * 获取对象
     * @param req
     * @return
     */
    @RequestMapping(value = "/getBtest",method = RequestMethod.POST)
    TBTest getBtest(@RequestBody BTestReq req){
        log.info("getBtest req: {}", JSON.toJSONString(req));
        return bRemoteService.getBtest(req);
    }
}
